package com.ty.day1.home;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/23 9:42
 */
public class Util {
    static Boolean judge(String str,String s){
        if (str.isEmpty()||s.isEmpty()){
            return null;
        }
        return str.endsWith(s);
    }
    static String[] deWeight(String[] str) {
        if (str==null){
            return null;
        }
        String[] s = new String[0];
        for (int i = 0; i < str.length; i++) {
            if (str[i]==null){
                continue;
            }
            boolean flag =true;
            for (int j = 0; j < s.length; j++) {
                if (str[i].equals(s[j])) {
                    flag=false;
                    break;
                }
            }
            if (flag) {
                s = Arrays.copyOf(s, s.length + 1);
                s[s.length-1]=str[i];
            }
        }
        return s;
    }
    static Integer count(String name, String s){
        if (name.isEmpty()||s.isEmpty()){
            return null;
        }
        int count =0,index=0;
        while (true) {
            index = name.indexOf(s, index);
            if (index!=-1){
                count++;
                index=index+s.length()+1;
            }else {
                break;
            }
        }
        return count;
    }
    static Boolean isHuiWen(String str){
        if (str==null){
            return null;
        }
        int length = str.length(),flag=1;
        for (int j = 0; j < length/2; j++) {
            if (str.charAt(j)!=str.charAt(length-1-j)){
                flag=0;
                break;
            }
        }
        if (flag==1){
            return true;
        }else {
            return false;
        }
    }
    static String[] isHuiWen(String[] str){
        if (str==null){
            return null;
        }
        String[] s=new String[0];
        for (int i = 0; i < str.length; i++) {
            int length = str[i].length(),flag=1;
            for (int j = 0; j < length/2; j++) {
                if (str[i].charAt(j)!=str[i].charAt(length-1-j)){
                    flag=0;
                    break;
                }
            }
            if (flag==1){
                s= Arrays.copyOf(s,s.length+1);
                s[s.length-1]=str[i];
            }
        }
        return s;
    }
}
